package com.fbee.smartcommunities.controller;

import com.fbee.smartcommunities.entity.Cart;
import com.fbee.smartcommunities.service.CartService;
import com.fbee.smartcommunities.utils.LocalDateTimeUtil;
import com.fbee.smartcommunities.vo.ResultVO;
import org.apache.tomcat.jni.Local;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 购物车 前端控制器
 * </p>
 *
 * @author 汪佳泉
 * @since 2024-08-26
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    private CartService cartService;

    @PostMapping("add")
    public ResultVO<Boolean> addGoodToCart(Long goodId,Long openId,Integer count){
        return ResultVO.success(cartService.addGoodToCart(goodId,openId,count),"成功添加至购物车");
    }

    @GetMapping("/getByUid")
    public ResultVO<List<Cart>> getCartsById(Long openId){
        return ResultVO.success(cartService.getCartByUid(openId));
    }

    @PostMapping("/deleteById")
    public ResultVO<Boolean> deleteById(Long cid){
        return ResultVO.success(cartService.removeById(cid),"成功移除购物车");
    }

}
